<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Articlecategory extends CI_Controller {

	public function index(){
	   $this->load->model('Articlecategories', null, true);
       $data['Articlecategories'] = $this->Articlecategories->getList();
	   $this->load->view('articlecategory/index', $data);
	}
    
    /**
     * function add customer
     * @author tien.nguyen
     */
    public function add(){
        $data = array();
        $this->load->model('ArticleCategories', null, true);
        
        //get post
        if($this->input->post()){
            $data = $this->input->post();
            //upload images
            if($this->ArticleCategories->add($data)){
                redirect(base_url().'articlecategory.html');
            }
            $data['Article'] = $data;
        }
        $data['optionCategory'] = $this->ArticleCategories->getOptions();
        //add none for category parent, because some item want is parent
        //$data['optionCategory'][''] = '';
        //ksort($data['optionCategory']);
        $this->load->view('articlecategory/add', $data);
    }
    
    /**
     * Delete customer
     * @author tien.nguyen
     */
    public function delete($articleId){
         $this->load->model('ArticleCategories', null, true);
         if($this->ArticleCategories->delete($articleId)){
            redirect(base_url().'articlecategory.html');
         }
    }
    
    /**
     * edit save config id
     * @author tien.nguyen
     */
    public function edit($articleCategoryId){
        $this->load->model('ArticleCategories', null, true);
        
        if($this->input->post()){
             $data = $this->input->post();             
            if($this->ArticleCategories->edit($data, $articleCategoryId)){
                redirect(base_url().'articlecategory.html');
            }
        }
        
        //get category
        $data['Articlecategory'] = $this->ArticleCategories->getArticleCategory($articleCategoryId);
        $data['optionCategory'] = $this->ArticleCategories->
            getOptions($data['Articlecategory']['NewsCategoryLevel']);
        //add none for category parent, because some item want is parent
        //$data['optionCategory'][''] = '';        
        //ksort($data['optionCategory']);
        
        $this->load->view('articlecategory/edit', $data);       
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */